# @Version        : 1.0
# @Update Time    : 2025/3/30 16:05
# @File           : user_utils.py
# @IDE            : PyCharm
# @Desc           : 用户上下文管理器
from .user_context import USER_MANAGER
from src.schemas.user_info_schema import UserInfo


class UserContextUtils:
    @staticmethod
    def set_user_info(user: UserInfo):
        """
        设置用户信息
        :param user: 用户信息
        :return:
        """
        USER_MANAGER.set(user)

    @staticmethod
    def get_user_info() -> UserInfo | None:
        """
        获取用户信息
        :return:
        """
        return USER_MANAGER.get()

    @staticmethod
    def get_user_id() -> int | None:
        """
        获取用户id
        :return:
        """
        user = USER_MANAGER.get()
        if user:
            return user.id
        return None

    @staticmethod
    def get_user_name() -> str | None:
        """
        获取用户名
        :return:
        """
        user = USER_MANAGER.get()
        if user:
            return user.username
        return None
